package com.swu.controller;

import com.swu.common.Result;
import com.swu.service.MedicalRecordValidationService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Tag(name = "病案首页校验", description = "病案首页规则校验相关接口")
@RestController
@RequestMapping("/medical-record")
@RequiredArgsConstructor
public class MedicalRecordValidationController {
    private final MedicalRecordValidationService validationService;

    @Operation(summary = "校验病案", description = "对指定病案进行规则校验")
    @GetMapping("/validate")
    public Result<List<String>> validate(
            @Parameter(description = "病案号", required = true)
            @RequestParam String medicalRecordId) {
        return validationService.validate(medicalRecordId);
    }

    @Operation(summary = "重新加载规则", description = "重新加载规则引擎中的规则")
    @GetMapping("/reload-rules")
    public Result<String> reloadRules() {
        try {
            validationService.reloadRules();
            return Result.success(null);
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }
} 